﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Warhammer40K_Simulator.view
{
    /// <summary>
    /// Interaction logic for unit.xaml
    /// </summary>
    public partial class unit : UserControl
    {
        public unit()
        {
            InitializeComponent();
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(unit_DataContextChanged);
        }

        void unit_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            bool showvehiclelabel = true;
            bool showcreaturelabel = true;
            stackpanel_figures.Children.Clear();
            model.unit u = e.NewValue as model.unit;

            foreach (model.figure f in u.Figures)
            {
                UserControl ui = null;
                if (f as model.creature != null)
                {
                    creature c = new creature();
                    c.labels.Visibility = (showcreaturelabel) ? Visibility.Visible : Visibility.Collapsed;
                    ui = c;
                    showcreaturelabel = false;
                    showvehiclelabel = true;
                }
                else if (f as model.vehicle != null)
                {
                    vehicle v = new vehicle();
                    v.labels.Visibility = (showvehiclelabel) ? Visibility.Visible : Visibility.Collapsed;
                    ui = v;
                    showvehiclelabel = false;
                    showcreaturelabel = true;
                }
                    
                ui.DataContext = f;
                stackpanel_figures.Children.Add(ui);
            }
        }
    }
}
